package com.bytedance.common.b;

import android.annotation.TargetApi;
import android.content.Context;
import android.location.Location;
import android.os.Build;
import android.webkit.WebSettings;
import android.webkit.WebView;

public final class UserAgentCompat {
    static class IMPL {
        private IMPL() {

        }

        public float getScale(WebView webview) {
            if (webview != null) {
                try {
                    return webview.getScale();
                } catch (Exception exception) {
                    return 1f;
                }
            } else {
                return 1f;
            }
        }

        public long getTime(Location location) {
            return location.getTime();
        }

        public String getUserAgent(Context context) {
            return null;
        }

        public void setMediaPlaybackRequiresUserGesture(WebSettings webSettings) {
        }
    }

    @TargetApi(value = 17)
    static final class IMPL17 extends UserAgentCompat.IMPL {
        private IMPL17() {
        }

        public final float getScale(WebView webView) {
            if (webView != null) {
                try {
                    return webView.getScale();
                } catch (Exception exception) {
                }
            }
            return 1f;
        }

        public final long getTime(Location location) {
            return location.getTime();
        }

        public final String getUserAgent(Context context) {
            try {
                return WebSettings.getDefaultUserAgent(context);
            } catch (Throwable throwable) {
               return null;
            }
        }

        public final void setMediaPlaybackRequiresUserGesture(WebSettings webSettings) {
            try {
                webSettings.setMediaPlaybackRequiresUserGesture(true);
            } catch (Throwable throwable) {
            }
        }
    }

    private static UserAgentCompat.IMPL IMPL = Build.VERSION.SDK_INT >= 17 ? new IMPL17() : new IMPL();

    public static float getScale(WebView webView) {
        return UserAgentCompat.IMPL.getScale(webView);
    }

    public static long getTime(Location location) {
        return UserAgentCompat.IMPL.getTime(location);
    }

    public static String getUserAgent(Context context) {
        return UserAgentCompat.IMPL.getUserAgent(context);
    }

    public static void setMediaPlaybackRequiresUserGesture(WebSettings webSettings) {
        UserAgentCompat.IMPL.setMediaPlaybackRequiresUserGesture(webSettings);
    }
}

